import os
import shutil

json_dir = "dataset/scene"
target_root = "dataset/rcs_0625/samples/"

# 获取所有 JSON 文件名（去掉后缀）
json_files = [f for f in os.listdir(json_dir) if f.endswith(".json")]
json_names = {os.path.splitext(f)[0]: f for f in json_files}

# 遍历：dataset/rcs_0625/samples/{日期}/{子任务名}/
for date_dir in os.listdir(target_root):
    date_path = os.path.join(target_root, date_dir)
    if not os.path.isdir(date_path):
        continue

    for sub_dir in os.listdir(date_path):
        full_path = os.path.join(date_path, sub_dir)
        if os.path.isdir(full_path) and sub_dir in json_names:
            src_file = os.path.join(json_dir, json_names[sub_dir])
            dst_file = os.path.join(full_path, "default.json")

            # 如果目标 default.json 已存在，先删除
            if os.path.exists(dst_file):
                os.remove(dst_file)
                print(f"Deleted existing {dst_file}")

            # 执行移动并改名
            shutil.move(src_file, dst_file)
            print(f"Moved and renamed {json_names[sub_dir]} -> {dst_file}")
